/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Server.ImplementInterface;

import Interface.IRemoteSavingBook;
import Server.DTO.SavingBook_DTO;
import static Server.ImplementInterface.SavingBookRepository.GetBookID;
import java.rmi.RemoteException;
import static java.rmi.server.RemoteServer.getClientHost;
import java.rmi.server.ServerNotActiveException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.rmi.server.UnicastRef;

/**
 *
 * @author 10520_000
 */
public class SavingBookObject extends UnicastRemoteObject implements IRemoteSavingBook{

    public SavingBookObject() throws RemoteException{
        super();
    }
    @Override
    public int Insert(SavingBook_DTO info) throws RemoteException {
        try {
            System.out.println("Invoke Insert from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return SavingBookRepository.Insert(info);
    }

    @Override
    public int Update(SavingBook_DTO info) throws RemoteException {
        try {
            System.out.println("Invoke Update from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return SavingBookRepository.Update(info);
    }

    @Override
    public int Delete(SavingBook_DTO info) throws RemoteException {
        try {
            System.out.println("Invoke Delete from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return SavingBookRepository.Delete(info);
    }

    @Override
    public ArrayList FindAll() throws RemoteException {
        try {
            System.out.println("Invoke FindAll from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return SavingBookRepository.FindAll();
    }
    
    @Override
    public SavingBook_DTO FindByBookID(String DetailID) throws RemoteException {
        try {
            System.out.println("Invoke Find By BookID from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return SavingBookRepository.FindByBookID(DetailID);
    }

    @Override
    public ArrayList GetSavingBooks(String str_fullname) throws RemoteException {
        ArrayList arr = null;
        try {
            arr = SavingBookRepository.GetSavingBooks(str_fullname);
        } catch (SQLException ex) {
            Logger.getLogger(SavingBookObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return arr;
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int CountSavingBook(String str_CustomerID) throws RemoteException {
        int result = 0;
        try {
            result = SavingBookRepository.CountSavingbooks(str_CustomerID);
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (SQLException ex) {
            Logger.getLogger(SavingBookObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
    public static void main(String []str) throws RemoteException
    {
        SavingBookObject obj = new SavingBookObject();
        System.out.println(obj.GetBookID("do ngoc sam", "215250401", "CO KY HAN", 3));
    }

    @Override
    public String GetBookID(String str_FullName, String str_IDNumber, String str_TypeName, int Term) throws RemoteException {
        String result = "";
        try {
            result = SavingBookRepository.GetBookID(str_FullName, str_IDNumber, str_TypeName, Term);
        } catch (SQLException ex) {
            Logger.getLogger(SavingBookObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
